/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cz.cvut.fel.taskpro.view.controller;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;

/**
 * This controller parse view data url and convert it to navigation text, which
 * is more user friendly to user. Controller is session scope and is called as
 * navigation.
 *
 * @author Tom
 * @version 1.0.0. beta
 */
@ManagedBean(name = "navigation")
@SessionScoped
public class NavigationBean extends AbstractController implements Serializable {

    private Map<String, String> navigationMap;

    /**
     * This method initialize class. Based on user role is made list of pages.
     */
    @PostConstruct
    public void init() {
        navigationMap = new HashMap<String, String>();
        recognizeLogin();
        if (loggedKantor != null) {
            fillMapKantor();
        } else if (loggedStudent != null) {
            fillMapStudent();
        } else if (loggedAdmin != null) {
            fillAdmin();
        }
    }

    /**
     * This method find in which page is current user and then return
     * appropriate page heading.
     */
    public String showLocation() {
        FacesContext cfc = FacesContext.getCurrentInstance();
        String path = cfc.getViewRoot().getViewId();
        path = navigationMap.get(path);
        return path;
    }

    /**
     * This method fill hash map students page. Key is actual user possition and
     * value is user friendly location.
     */
    private void fillMapStudent() {
        navigationMap.put("/Student/reportStudent.xhtml", "Student - Reports");
        navigationMap.put("/Student/profilStudent.xhtml", "Student - Profil");
        navigationMap.put("/Student/studentTeam.xhtml", "Student - Teams");
        navigationMap.put("/Student/submitTaskStudent.xhtml", "Student - Submit task");
        navigationMap.put("/Student/submittedTasksStudent.xhtml", "Student - Submitted task");
        navigationMap.put("/Student/taskToSubmit.xhtml", "Student - Task to submit");
        navigationMap.put("/Student/welcomePageStudent.xhtml", "Student - Welcome page");
        navigationMap.put("/Student/help.xhtml", "Student - Help");
    }

    /**
     * This method fill hash map kantors page. Key is actual user possition and
     * value is user friendly location.
     */
    private void fillMapKantor() {
        navigationMap.put("/Kantor/assignTaskConfirm.xhtml", "Assign task step 3 confirm assignments");
        navigationMap.put("/Kantor/assignTaskKantor.xhtml", "Assign task step 2 choose users to assign");
        navigationMap.put("/Kantor/createTaskKantor.xhtml", "Create template");
        navigationMap.put("/Kantor/createTeam.xhtml", "Create team");
        navigationMap.put("/Kantor/createTeamConfirm.xhtml", "Confirm team creation");
        navigationMap.put("/Kantor/editAssignmentsKantor.xhtml", "Edit assignments");
        navigationMap.put("/Kantor/editTemplate.xhtml", "Edit template");
        navigationMap.put("/Kantor/profilKantor.xhtml", "Profil");
        navigationMap.put("/Kantor/rateTask.xhtml", "Rate task");
        navigationMap.put("/Kantor/rateTaskSum", "Task to rate by criteria");
        navigationMap.put("/Kantor/reportKantor.xhtml", "Students final reports");
        navigationMap.put("/Kantor/showStudents.xhtml", "Assigned students to kantor");
        navigationMap.put("/Kantor/showTeam.xhtml", "Teams created by kantor");
        navigationMap.put("/Kantor/welcomePageKantor.xhtml", "Welcome page");
        navigationMap.put("/Kantor/addStudentToTeam.xhtml", "Add student to team");
        navigationMap.put("/Kantor/teamModification.xhtml", "Modify team");
        navigationMap.put("/Kantor/submittedTaskKantor.xhtml", "Recently submitted tasks");
        navigationMap.put("/Kantor/assignTemplate.xhtml", "Task list - assign task , step 1 choose or create template");
    }

    /**
     * This method fill hash map admin page. Key is actual user possition and
     * value is user friendly location.
     */
    private void fillAdmin() {
        navigationMap.put("/Admin/addParallelAdmin.xhtml", "Admin - Create group");
        navigationMap.put("/Admin/addSubjectAdmin.xhtml", "Admin - Create subject");
        navigationMap.put("/Admin/addUserAdmin.xhtml", "Admin - Add user");
        navigationMap.put("/Admin/checkAllSubjectAdmin.xhtml", "Admin - All subject in system");
        navigationMap.put("Admin/checkKantorsAdmin.xhtml", "Admin - All kantors in system");
        navigationMap.put("/Admin/checkStudentsAdmin.xhtml", "Admin - All students in system");
        navigationMap.put("/Admin/modifyUserAdmin.xhtml", "Admin - Modify user");
        navigationMap.put("/Admin/profilAdmin.xhtml", "Admin - Personal profile");
        navigationMap.put("/Admin/welcomePageAdmin.xhtml", "Admin - Welcome page");
        navigationMap.put("/Admin/systemEnviroment.xhtml", "Admin - Application setting");
        navigationMap.put("/Admin/modifyGroup.xhtml", "Admin - Modify group");
    }
}
